package problems;

import java.math.BigInteger;

public class Euler063 extends AbstractEuler {

	@Override
	public Number calculate() {
		//The number that we are raising to a power can never be greater than 9, because the length of 10^n is always n+1.
		//Also, the number of the power can never be greater than 21, because 9^21 is 21 long, but so is 9^22,
		//and when increasing the power any further, the length will never be as great as the power, because 9 < 10.
		//The length of 8^21 is shorter than 21, and so the length of x^21 for smaller values of x will be yet smaller.
		//The lower bound for both the number being raised to a power and the power itself must be 1, because
		//x^0 is 1 (so no numbers will satisfy the condition there), and
		//0^x is 0, which is of length 1. An exception might be 0^1, which is of length 1, and by most definitions positive,
		//but apparently not in this case.
		//this gives rise to the following algorithm:
		
		int positiveIntegersWhichAreNthPower = 0;
		for (int number = 1; number < 10; number++) {
			for (int power = 1; BigInteger.valueOf(number).pow(power).toString().length() == power; power++) {
				positiveIntegersWhichAreNthPower++;
			}
		}
		
		return positiveIntegersWhichAreNthPower;
	}

	@Override
	protected Number getCorrectAnswer() {
		return 49;
	}

}
